/*  ----------------------------------------------------------------------------
*	This file is part of the AS3This ActionScript 3 library.
*	Author: Steve Jones for G-RAFF <http://www.g-raff.com/>
*	Copyright (c) 2009 raffWorks Ltd.
*	----------------------------------------------------------------------------
*	Please see the notice at the bottom of the code before using or modifying this class.
*/
package com.as3this.ui
{
	import flash.display.DisplayObject;
	import flash.display.Stage;
	import flash.geom.Point;
	
	/**
	 * Utility class that provides values for sharing menu positions.
	 */
	 
	public class MenuAlign
	{
		public static const TOP_LEFT		:String = "top/left";
		public static const TOP_CENTER		:String = "top/center";
		public static const TOP_RIGHT		:String = "top/right";
		
		public static const BOTTOM_LEFT		:String = "bottom/left";
		public static const BOTTOM_CENTER	:String = "bottom/center";
		public static const BOTTOM_RIGHT	:String = "bottom/right";
		
		/**
		 * Returns an actual X/Y position for the menu based on the size of the UI display and the stage containing it
		 * 
		 * @param 	stage		The stage containing the SWF content (and the menu itself)
		 * @param	alignment	Position of the menu on the stage
		 * @param	menu		The actual DisplayObject of the sharing menu
		 * @param	padding		An object containing optional padding parameters to push the menu away from the stage edges
		 */
		
		public static function getPosition(stage:Stage, alignment:String, menu:DisplayObject = null, padding:Object = null) : Point
		{
			var pos:Point = new Point();
			
			var alignSplit:Array = alignment.split("/");
			pos.x = getX(alignSplit[1], padding || {});
			pos.y = getY(alignSplit[0], padding || {});
			
			function getX(align:String, padding:Object) : Number
			{
				switch(align) 
				{
					case "left" :
						return padding.paddingLeft || 0;
					case "center" :
						return stage.stageWidth/2 - menu.width/2;
					case "right" :
						return stage.stageWidth - menu.width - (padding.paddingRight || 0);
				}
				return 0;
			}
			
			function getY(align:String, padding:Object) : Number
			{
				switch(align) 
				{
					case "top" :
						return padding.paddingTop || 0;
					case "bottom" :
						return stage.stageHeight - menu.height - (padding.paddingBottom || 0);
				}	
				return 0;
			}
			return pos;
		}
	}
}

/*
 *    AS3This is free software: you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    AS3This is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License
 *    along with AS3This.  If not, see <http://www.gnu.org/licenses/>.
 */